package com.loop.unclelend.utils.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.loop.unclelend.R
import com.loop.unclelend.databinding.UncleDialogBindCardDeleteBinding
import com.loop.unclelend.pro.ProDialog
import com.loop.unclelend.utils.ImageUtil
import com.loop.unclelend.utils.event.UncleEventHelper
import com.loop.unclelend.utils.event.UncleEventType
import org.json.JSONObject

/**
 * UncleLend
 * @Author wwdeng
 * @CreateTime: 2024/9/20 13:45
 * @Annotation：绑卡删除dialog
 */
class Dialog_BindCard_Delete: ProDialog {
    private lateinit var binding: UncleDialogBindCardDeleteBinding
    private var mCallback: IDialogCallback? = null

    //事件备注
    private var eventRemark = ""

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String,callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }


    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = UncleDialogBindCardDeleteBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(binding.btnCancel)
        setOnClickListener(binding.btnSubmit)
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        when(v!!.id){
            R.id.btn_cancel -> {
                UncleEventHelper.addUncleRequestEventAction(UncleEventType.CLICK.UNCLE_CLICK_USER_ACCOUNT_DELETE_TIPS_CANCEL,eventRemark)
            }
            else -> {
                UncleEventHelper.addUncleRequestEventAction(UncleEventType.CLICK.UNCLE_CLICK_USER_ACCOUNT_DELETE_TIPS_CONFIRM,eventRemark)
            }
        }
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置需要删除的账户信息
     */
    @SuppressLint("SetTextI18n")
    fun setBindAccountInfo(info: JSONObject){
        ImageUtil.instance!!.loadImageUrl(context,binding.layoutAccount.imgLogo,info.optString("walletLogo"), R.mipmap.icon_holder)
        binding.layoutAccount.txtTitle.text = info.optString("walletDesc")
        binding.layoutAccount.txtAccount.text = "+" + info.optString("walletMobile")
        //不显示删除
        binding.layoutAccount.imgDelete.visibility = View.INVISIBLE
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        UncleEventHelper.addUncleRequestEventAction(UncleEventType.DIALOG.UNCLE_DIALOG_USER_ACCOUNT_DELETE_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        UncleEventHelper.addUncleRequestEventAction(UncleEventType.DIALOG.UNCLE_DIALOG_USER_ACCOUNT_DELETE_TIPS_DISMISS,eventRemark)
    }
}